#include <iostream>
#include <vector>
using namespace std;

template<class T>
class Less
{
public:
    bool operator()(const T& a, const T& b)
    {
        return a > b;
    }
};

template<class T>
class Greater
{
public:
    bool operator()(const T& a, const T& b)
    {
        return a < b;
    }
};

template<class T, class Con = vector<T>, class Cmp = Less<T>>
class PriorityQueue
{
public:
    void Push(const T& x)
    {
        _con.push_back(x);
        AdjustUp(_con.size() - 1);
    }

    void Pop()
    {
        std::swap(_con[0], _con[_con.size() - 1]);
        _con.pop_back();
        AdjustDown(0);
    }

    T& Top()
    {
        return _con[0];
    }

    size_t size()
    {
        return _con.size();
    }
private:
    void AdjustUp(int child)
    {
        int parent = (child - 1) / 2;
        while(child > 0)
        {
            if(_cmp(_con[child], _con[parent]))
            {
                std::swap(_con[child], _con[parent]);
                child = parent;
                parent = (child - 1) / 2;
            }
            else
            {
                break;
            }
        }
    }

    void AdjustDown(int parent)
    {
        int child = parent * 2 + 1;
        while(child < size())
        {
            if(child + 1 < size() && _cmp(_con[child + 1], _con[child]))
            {
                child++;
            }
            if(_cmp(_con[child], _con[parent]))
            {
                std::swap(_con[child], _con[parent]);
                parent = child;
                child = parent * 2 + 1;
            }
            else
            {
                break;
            }
        }
    }

    Cmp _cmp;
    Con _con;
};